package com.tbs.easyhomemoneyserver.utils

import java.util.function.Function

object SysUtils {
//    /**
//     * 拦截器产生的异常的抛出处理
//     *
//     * @param e        异常
//     * @param request  请求
//     * @param response 相应
//     * @throws ServletException
//     * @throws IOException
//     */
//    @JvmStatic
//    @Throws(ServletException::class, IOException::class)
//    fun throwError(e: Throwable?, request: ServletRequest, response: ServletResponse?) {
//        request.setAttribute(CommonConstants.ERROR_ATTR_NAME, e)
//        // 指定处理该请求的处理器
//        request.getRequestDispatcher(CommonConstants.ERROR_PATH).forward(request, response)
//    }


    @JvmStatic
    fun <T> ColToString(collection: Collection<T>, f: Function<T, String?>, connector: String = ","): String {
        var isFirst = true
        val sb = StringBuilder()
        for (t in collection) {
            if (isFirst) {
                sb.append(f.apply(t));
                isFirst = false;
            } else {
                sb.append(connector).append(f.apply(t));
            }
        }
        return sb.toString();
    }
}
